Ext.define('MyDesktop.GridWindow', {
    extend: 'Ext.ux.desktop.Module',

    requires: [
        'Ext.data.ArrayStore',
        'Ext.util.Format',
        'Ext.grid.Panel',
        'Ext.grid.RowNumberer'
    ],
    id:'grid-win',
    init : function(){
        this.launcher = {
            text: 'Grid Window',
            iconCls:'icon-grid'
        };
    },
    
    //页面显示主窗口
    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('user');
        if(!win){
            win = desktop.createWindow({
                id: 'user',
                title:'用户管理',
                width:740,
                height:500,
                iconCls: 'icon-grid',
                animCollapse:false,
                constrainHeader:true,
                layout: 'fit',
                items: [
                    {
                        border: false,
                        xtype: 'grid',
                        store: new Ext.data.ArrayStore({
                            fields: [
                               { name: 'name' },
                               { name: 'age', type: 'float' },
                               { name: 'tel', type: 'float' }
                            ],
                            data: MyDesktop.GridWindow.getDummyData()
                        }),
                        columns: [
                            new Ext.grid.RowNumberer(),
                            {
                                text: "姓名",
                                flex: 1,
                                sortable: true,
                                dataIndex: 'name'
                            },
                            {
                                text: "年龄",
                                //width: 70,
                                sortable: true,
                                //renderer: Ext.util.Format.usMoney,//前面带个$
                                dataIndex: 'age'
                            },
                            {
                                text: "电话",
                                width: 170,
                                sortable: true,
                                dataIndex: 'tel'
                            }
                        ]
                    }
                ],
                tbar:[{
                    text:'增加',
                    tooltip:'增加新用户',//鼠标放上去时显示的内容
                    iconCls:'add',
                    handler:function(){
                		var add_win = new Ext.Window({
                			title:'添加用户',
                			width:300,
                			items:user_add,
                			buttons: [{
                				text: '确定',
                				handler:function(){
                					Ext.Msg.alert("提示","添加成功");
                					add_win.close(this);
                				}
                			},{
                				text: '重置',
                				handler:function(){
                					Ext.getCmp('username').reset();
                					Ext.getCmp('age').reset();
                					Ext.getCmp('tel').reset();
                				}
                			}]
                		});
                		add_win.show(this);
                	}
                }, '-', {
                    text:'编辑',
                    tooltip:'编辑用户',//鼠标放上去时显示的内容
                    iconCls:'option',
                    handler:function(){
	                	var row=Ext.getCmp('user').getSelectionModel().getSelected();
	                	alert(row);
	                	if(1!=1){
	        				
	        			}else{
	        				var add_win = new Ext.Window({
	                			
	                			title:'编辑用户',
	                			width:300,
	                			items:user_add,
	                			buttons: [{
	                				text: '确定',
	                				handler:function(){
	                					Ext.Msg.alert("提示","编辑成功");
	                					add_win.close(this);
	                				}
	                			}]
	                		});
	                		add_win.show(this);
	    	            	}
	        			}
            		
                },'-',{
                    text:'删除',
                    tooltip:'删除用户',//鼠标放上去时显示的内容
                    iconCls:'remove',
                    handler:function(){
	            		Ext.Msg.alert("删除用户","准备删除");
	            	}
                }]
            });
        }
        return win;
    },
    //测试数据
    statics: {
        getDummyData: function () {
            return [
                ['杨飞',98,'134061811'],
                ['郭娜',65,'1861068625'],
                ['高志强',35,'14821725712']
            ];
        }
    }
});

